<template>
    giteeLogin
</template>
<script setup>
import {userLoginByGitee} from '@/api/user.js'
import {useRouter} from "vue-router";
import {inject} from "vue";
import {ElMessage} from "element-plus";
const router = useRouter();
var url = window.location.href ;//获取当前url
const isSignIn=inject('isSignIn')
var cs_arr = url.split('#')[0].split('?')[1].split('&');//参数字符串分割为数组
var cs={};
for(var i=0;i<cs_arr.length;i++){//遍历数组，拿到json对象
    cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
}

var code = cs.code;
// console.log(code)
const loginByGitee = async ()=>{
  let result = await userLoginByGitee(code);
  if(result.status === 1){
    console.log(result.data)
    localStorage.setItem("token", result.data.token);
    localStorage.setItem("username", result.data.username);
    isSignIn.value='true';
    await router.push('/main');

  }else{
    ElMessage.error(result.message);
    await router.push('/login');
  }
}
loginByGitee();
</script>